package com.htwy.ext;

import com.htwy.kits.CommonKit;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;

/**
 * Created by jzgw2 on 2017/5/5.
 */
public class SqlWhereDirective extends ExtDirective {
    @Override
    public void exec(Env env, Scope scope, Writer writer) {
        String content = getContent(env, scope);
        if(content.length() > 0){
            content = CommonKit.trimSpace(content);
            if(content.length() > 0) {
                write(writer, " WHERE ");
                if (content.substring(0, 3).equalsIgnoreCase("and")) {
                    write(writer, content.substring(3));
                } else {
                    write(writer, content);
                }
                write(writer, " ");
            }
        }
    }
    @Override
    public boolean hasEnd() {
        return true;
    }
}